`timescale 1ns / 1ps
/*
 Copyright 2020 Sean Xiao, jxzsxsp@qq.com
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
 http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

module yue_sync # (
    parameter DP = 2,
    parameter DW = 32
)
(
    input  [ DW - 1: 0 ] din_a,
    output [ DW - 1: 0 ] dout,

    input  clk,
    input  rst_n
);

wire [ DW - 1: 0 ] sync_dat [ DP - 1: 0 ];

genvar i;

generate
    for ( i = 0; i < DP; i = i + 1 )
    begin: sync_gen
        if ( i == 0 )
        begin: i_is_0
            yue_dffr #( DW ) sync_dffr( din_a, sync_dat[ 0 ], clk, rst_n );
        end
        else
        begin: i_is_not_0
            yue_dffr #( DW ) sync_dffr( sync_dat[ i - 1 ], sync_dat[ i ], clk, rst_n );
        end
    end
endgenerate

assign dout = sync_dat[ DP - 1 ];

endmodule
